package com.translate.callback;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;

import org.springframework.data.redis.core.RedisTemplate;

import com.translate.web.config.SpringBeanUtil;
import com.translate.entity.ApprovalFlowPath;
import com.translate.entity.User;
import com.translate.web.service.IApprovalFlowPathService;
import com.translate.web.service.IUserService;

/**
 * 投递审核消息
 * @author 111
 */
public class OrderByDeliveryReviewMessage implements Callable<Integer> {

	
	private Integer userId;
	private Integer id;
	

	/**
	 * 
	 * @param message 审核消息
	 * @param type 审核类型
	 * @param id 参数
	 */
	public OrderByDeliveryReviewMessage(Integer userId, Integer id) {
		this.id = id;
		
		this.userId = userId;
	}
	
	@Override
	public Integer call() throws Exception {

		RedisTemplate<String, String> redisTemplate = SpringBeanUtil.getBean("redisTemplate");
		
		Map<String, Object> map = new HashMap<>();
		
		map.put("action", "approval");
		
		map.put("type", "receivables");
		
		map.put("id", id);
		
		map.put("type", "receivables");
		
		IApprovalFlowPathService approvalService = SpringBeanUtil.getBean(IApprovalFlowPathService.class);
		
		List<ApprovalFlowPath> approvalFlowPathos = approvalService.getApprovalFlowPathFromCache("Order");
		
		ApprovalFlowPath approvalFlowPath = approvalFlowPathos.get(0);
		
		IUserService userService = SpringBeanUtil.getBean(IUserService.class);
		
		User user = userService.getUserInfoToCache(this.userId);
		
		map.put("message", "待审批 - " + user.getRealname() + "回款信息确认");
		
		map.put("approvalUserId", approvalFlowPath.getApprovalId());
		
		redisTemplate.convertAndSend("ORDER_TOPIC", map);
		
		return 0;
	}

}
